<?php
class taobao extends spController{
	private $AKEY = '12310646';
	private $SKEY = 'b60adc8d397f1c40b3944bc102f9c0ab';
	
	function call(){
		$o = spClass('TaobaoOAuth',array($this -> AKEY,$this -> SKEY));
		$alink = $o -> getAuthorizeURL($_SERVER['SCRIPT_URI'].'?c=taobao&a=back');
		echo 'Jump to Taobao,Wait.';
		$this -> jump($alink,2);
	}
	
	function back(){
		$o = spClass('TaobaoOAuth',array($this -> AKEY,$this -> SKEY));
		$sign = $o -> verifysign($this -> spArgs('top_appkey'),$this -> spArgs('top_parameters'),$this -> spArgs('top_session'));
		if($sign != $this -> spArgs('top_sign')){
			$this->error('登录失败');
		}
		else{
			$info = base64_decode($this -> spArgs('top_parameters'));
			parse_str($info,$infos);
			if (!empty($infos['visitor_nick'])){
				$result = spClass('libICase') -> acl_connect_login('TAOBAO',$infos['visitor_nick'],$infos['visitor_nick'],spClass('spICase')->get(),'');
				if($result > 0){
					spClass('spICase') -> set($result);
					$this->success('登录成功',spUrl());//这里填写跳转地址
				}
				elseif($result == '-11'){
					$_SESSION['tmp_webuser'] = $infos['visitor_nick'];
					$_SESSION['tmp_webusername'] = $infos['visitor_nick'];
					$this -> display('taobao_register.html');
				}
				else{
					echo '错误码'.$result;
					die();
				}
			}
		}
	}
	
	function emailregister(){
		$result = spClass('libICase') -> acl_connect_login('TAOBAO',$_SESSION['tmp_webuser'],$_SESSION['tmp_webusername'],NULL,$this->spArgs('email'));
		if($result > 0){
			spClass('spICase') -> set($result);
			$this->success('登录成功',spUrl());//这里填写跳转地址
		}
		elseif($result == '-11'){
			$this -> display('taobao_register.html');
		}
		else{
			echo '错误码'.$result;
			die();
		}
	}
	
	function loginregister(){
		$login = spClass('libICase') -> acl_user_login($this -> spArgs('uname'),$this -> spArgs('upass'));
		if($login['id'] > 0){
			$result = spClass('libICase') -> acl_connect_login('TAOBAO',$_SESSION['tmp_webuser'],$_SESSION['tmp_webusername'],$login['id']);
			spClass('spICase') -> set($result);
			$this->success('登录成功',spUrl());//这里填写跳转地址
		}
		else{
			$this -> display('taobao_register.html');
		}
	}
}